package cn.kgc.springmvc03.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/5/8
 * @Description: springmvc异常的处理机制  局部处理方案  @ExceptionHandler   只针对本类中的异常有效
 */

@RestController
@RequestMapping("student")
public class StudentController {



    //@ExceptionHandler(ArithmeticException.class)
    //public Map arithmeticExceptionHandler(ArithmeticException e){
    //    //打印异常信息
    //    e.printStackTrace();
    //    HashMap<String, Object> map = new HashMap<>();
    //    map.put("code",500);
    //    map.put("msg","数学运算异常");
    //    return map;
    //}

    @RequestMapping("m1")
    public Map  method1(){

        HashMap<String, Object> map = new HashMap<>();

        //ArithmeticException:
        int i = 1/0;
        map.put("code",200);
        map.put("msg","ok");
        return  map;

    }


    @RequestMapping("m2")
    public Map  method2(){
        HashMap<String, Object> map = new HashMap<>();

       String str = null;
       str.toUpperCase();
        map.put("code",200);
        map.put("msg","ok");
        return  map;
    }


}
